<?php namespace Summer\Hub\FormWidgets;

use Flash;
use Config;
use Backend\Classes\FormField;
use Backend\Classes\FormWidgetBase;

class Showimg extends FormWidgetBase
{
    protected $defaultAlias = 'showimg';

    /**
     * @var int Preview image width
     */
    public $imageWidth;

    /**
     * @var int Preview image height
     */
    public $imageHeight;

    public function render() {
        $this->prepareVars();
        return $this->makePartial('showimg');
    }

    /**
     * @inheritDoc
     */
    public function init()
    {
        $this->fillFromConfig([
            'imageWidth',
            'imageHeight'
        ]);
    }

    /**
     * Prepares the list data
     */
    public function prepareVars()
    {
        $value = $this->getLoadValue();
        $this->vars['value'] = $value;
        $this->vars['imageUrl'] = url('/storage/app/'.$value);
        $this->vars['imageWidth'] = $this->imageWidth;
        $this->vars['imageHeight'] = $this->imageHeight;
    }

    /**
     * @inheritDoc
     */
    protected function loadAssets()
    {
        $this->addCss('css/mediafinder.css', 'core');
    }

}
